package stool.iteratorpattern;

/**
 * @Author Felix YF Dong
 * @Date 2021/5/11
 */
public class ConcreteIterator extends Iterator{

    private ConcreteAggregate concreteAggregate;

    private int current = 0;

    public ConcreteIterator(ConcreteAggregate concreteAggregate) {
        this.concreteAggregate = concreteAggregate;
    }

    @Override
    public Object first() {
        return concreteAggregate.get(current);
    }

    @Override
    public Object next() {

        Object obj = null;
        current ++;
        if (current < concreteAggregate.size()) {
            obj = concreteAggregate.get(current);
        }

        return obj;
    }

    @Override
    public boolean isDone() {
        return current >= concreteAggregate.size();
    }

    @Override
    public Object current() {
        return concreteAggregate.get(current);
    }
}
